package com.jstide.credit.data.service.biz;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import com.jstide.credit.data.service.Algorithm;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class Factor23 extends Algorithm {

    private static final Logger logger = LoggerFactory.getLogger(Factor23.class);

    @Getter
    public final  String name="23";

    //判决日期开始1年内-120分；第二年-100分；第三年-80分，第四年-60分；第五年及以后-30分
    //-120
    //按时间判断
    @Getter
    public  final String sql =" select PJRQ from ZRRXSPJXX where join_id=@joinId  order by PJRQ desc ";

    @Override
    public int translate(String rs) {
        return 0;
    }


    @Override
    public int translate(List<Entity> rs) {
        int score = 0;
        if(null!=rs && rs.size()>0){
            try {
                List<Date> dateList = rs.stream().map(k -> k.getDate("PJRQ")).collect(Collectors.toList());
                for(Date date : dateList){
                    if(null!=date) {
                        int year = DateUtil.ageOfNow(date);
                        if(year<1){
                            return -120;
                        }
                        else if(year>=1 && year<2){
                            return -100;
                        }
                        else if(year>=3 && year <4){
                            return -80;
                        }
                        else if(year>=4 && year <5 ){
                            return -60;
                        }
                        else if(year>=5){
                            return -30;
                        }
                    }

                }
            }catch (Exception e){
                score=0;
            }
        }
        return score;
    }
}
